import httpRequest from "@/utils/http-request.js";

/**
 * 用户登录
 * @param username
 * @param password
 * @returns {*}
 */
export const login = ({username, password}) => {
    return httpRequest.post("/v1/sys/user/login", {
        username,
        password
    });
}

/**
 * 获取用户信息
 * @returns {*}
 */
export const profile = () => {
    return httpRequest.get("/v1/sys/user/profile");
}

/**
 * 分页查询
 * @param current
 * @param size
 * @returns {*}
 */
export const page = (current, size) => {
    return httpRequest.get("/v1/sys/user/page", {
        params: {
            current,
            size
        }
    });
}

/**
 * 新增
 * @param username
 * @param deptNo
 * @param roleIds
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const add = ({username, deptNo, roleIds}) => {
    return httpRequest.post("/v1/sys/user", {
        username,
        deptNo,
        roleIds
    });
}

/**
 * 根据ID修改
 * @param id
 * @param username
 * @param deptNo
 * @param roleIds
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const modifyById = (id, {username, deptNo, roleIds}) => {
    return httpRequest.put(`/v1/sys/user/${id}`, {
        username,
        deptNo,
        roleIds
    });
}

/**
 * 详情
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const detailById = (id) => {
    return httpRequest.get(`/v1/sys/user/detail/${id}`);
}

/**
 * 根据ID删除
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const deleteById = (id) => {
    return httpRequest.delete(`/v1/sys/user/${id}`);
}